//
//  ViewController.m
//  XHAdSDKTest
//
//  Created by 陈俭红 on 2022/1/5.
//

#import "ViewController.h"
//M

//V
#import "TableViewCell.h"
//C
#import "XHSplashListViewController.h"
#import "XHInterListViewController.h"
#import "XHRewardListViewController.h"
#import "XHBannerListViewController.h"

#import "XHCSJFeedViewController.h"
#import "XHDrawAdViewController.h"
#import "XHKSDrawAdViewController.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, copy)NSArray * dataArray;
@end

@implementation ViewController

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"广告";
    
    [self addAllViews];
    
    [self setDefaultData];
}

//MARK: Custom Methods
- (void)addAllViews{
    [self.view addSubview:self.tableView];
}

- (void)setDefaultData{
    self.dataArray = @[
        @{@"title":@"开屏广告(SPLASHAD)", @"des":@"1"},
        @{@"title":@"插屏广告(INTERACTIONAD)", @"des":@"2"},
        @{@"title":@"BANNER广告", @"des":@"3"},
        @{@"title":@"激励视频广告(REWARDVIDEO)", @"des":@"4"},
        @{@"title":@"信息流广告", @"des":@"7"},
        @{@"title":@"draw广告", @"des":@"8"},
        @{@"title":@"快手draw广告", @"des":@"9"},
    ];
    [self.tableView reloadData];
}

//MARK: Getter Methods
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"TableViewCell"];
    }
    return _tableView;
}

//MARK: UITableViewDelegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
    cell.dic = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic = self.dataArray[indexPath.row];
    NSString * des = dic[@"des"];
    if ([des isEqualToString:@"1"]) {
        XHSplashListViewController * vc = [XHSplashListViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([des isEqualToString:@"2"]) {
        XHInterListViewController * vc = [XHInterListViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([des isEqualToString:@"3"]) {
        XHBannerListViewController * vc = [XHBannerListViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    if ([des isEqualToString:@"4"]) {
        XHRewardListViewController * vc = [XHRewardListViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    }
   
    if ([des isEqualToString:@"7"]) {
        XHCSJFeedViewController *vc = [[XHCSJFeedViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([des isEqualToString:@"8"]) {
        XHDrawAdViewController *vc = [[XHDrawAdViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if ([des isEqualToString:@"9"]) {
        XHKSDrawAdViewController *vc = [[XHKSDrawAdViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
@end


